package com.easytool.modules.front.service;

import com.easytool.model.dto.FileUploadInfo;
import com.easytool.utils.BaiDuOcrUtil;
import com.easytool.utils.UploadUtil;
import com.jfinal.upload.UploadFile;
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 这是一个类
 *
 * @author liupengtao
 * @date 2019/12/18
 */
public class ImgTextService {

    UploadUtil uploadUtil = UploadUtil.me;


    public List<Object> basicGeneral(UploadFile file){

        FileUploadInfo fileUploadInfo = uploadUtil.fileUpload("imgText",file);
        String imgPath = fileUploadInfo.getAbsolutePath() + "/" + fileUploadInfo.getFileName();
        JSONObject jsonObject = BaiDuOcrUtil.basicGeneral(imgPath);
        JSONArray wordsResultArray = jsonObject.getJSONArray("words_result");
        if(wordsResultArray == null || wordsResultArray.length() == 0){
            return new ArrayList<>();
        }

        List<Object> wordsResult = wordsResultArray.toList();

        return wordsResult;
    }

}
